
local NO_AURA_ICON = 'Interface/Icons/INV_Misc_QuestionMark.blp'
local aura = nil
local events = {}

function UpdateAura()
   local icon
   local form = GetShapeshiftForm()
   if form > 0 then
      local tex, name = GetShapeshiftFormInfo(form)
      if name then
         icon = GetSpellTexture(name)
      end
   end
   
   if not icon then
      icon = 'Interface/Icons/INV_Misc_QuestionMark.blp'
   end
   
   aura.texture:SetTexture(icon)
end

function events:UPDATE_SHAPESHIFT_FORM()
   return UpdateAura()
end

function events.UPDATE_SHAPESHIFT_FORMS(self)
   return UpdateAura()
end

function events.PLAYER_ENTERING_WORLD(self)
   return UpdateAura()
end

-- function events.PLAYER_LOGIN(self)
   -- return UpdateAura()
-- end

local function InitPlayer()
   local _, class = UnitClass("player")
   if class ~= 'PALADIN' then
      return
   end
   
   aura = CreateFrame('FRAME', 'SpyAura')
   Spy.ManageFrame(aura)
   local size = 40
   aura:SetWidth(size)
   aura:SetHeight(size)
   aura.texture = aura:CreateTexture(nil, 'ARTWORK')
   aura.texture:SetAllPoints()
   aura.texture:SetTexture(NO_AURA_ICON)
   -- aura:SetPoint('TOPLEFT', PlayerFrame, 'TOPLEFT', 100, -100)

   Spy.RegisterEvents(aura, events)
end

--Spy.AddStartupFunc(InitPlayer)
